package com.jf3q.sup.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.sup.domain.PurchaseDetails;
import com.jf3q.sup.dto.PurchaseDetailsDto;
import com.jf3q.sup.dto.PurchasesAddDto;
import com.jf3q.sup.service.PurchaseDetailsService;
import com.jf3q.sup.mapper.PurchaseDetailsMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *
 */
@Service
public class PurchaseDetailsServiceImpl extends ServiceImpl<PurchaseDetailsMapper, PurchaseDetails>
    implements PurchaseDetailsService{


    @Autowired
    PurchaseDetailsMapper purchaseDetailsMapper;

    @Override
    public void addDetails(PurchasesAddDto addDto) {
        try {
            for (PurchaseDetailsDto detailsDto : addDto.getDetailsDtoList()) {
                PurchaseDetails purchaseDetails = new PurchaseDetails();
                BeanUtils.copyProperties(detailsDto,purchaseDetails);
                purchaseDetails.setPurchaseId(addDto.getPurId());
                purchaseDetails.setCreatedAt(new Date(System.currentTimeMillis()));
                purchaseDetails.setUpdatedAt(new Date(System.currentTimeMillis()));
                purchaseDetailsMapper.insert(purchaseDetails);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}




